package com.fs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.pojo.Customer;
import com.fs.service.Customerservice;
import com.fs.util.ResponseDataUtil;
import com.fs.vo.Condition;
import com.fs.vo.ResponseData;
import com.fs.vo.ResultEnums;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/reverse/customer")
public class CustomerController {
    @Resource
    private Customerservice customerservice;
    /**
     * 删除客户表的方法
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseData delCustomer(@PathVariable Integer id){
        Integer result = customerservice.deleteCustomer(id);
        return result!=0? ResponseDataUtil.buildOk("200","删除成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 添加客户的方法
     * @param customer
     * @return
     */
    @PostMapping
    public ResponseData addCustomer(@RequestBody Customer customer){
        Integer result = customerservice.addCustomer(customer);
        return result!=0?ResponseDataUtil.buildOk("200","新增成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 更新客户的方法
     * @param customer
     * @return
     */
    @PostMapping("update")
    public ResponseData updateCustomer(@RequestBody Customer customer){
        Integer result = customerservice.updateCustomer(customer);
        return result!=0?ResponseDataUtil.buildOk("200","修改成功"):ResponseDataUtil.buildFail(null);
    }



    /**
     * 查询客户表单
     * @param  id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseData queryCustomer(@PathVariable Integer id){
        Customer customerPage = customerservice.queryCustomerById(id);
        return customerPage!=null?ResponseDataUtil.buildOk(customerPage):ResponseDataUtil.buildFail(null);
    }

//    @PostMapping
//    public List<WhTransfer> queryAll(){
//        List<WhTransfer> transfers = whTransferService.queryAll();
//        return transfers;
//    }

    /**
     * 分页查询
     * @param condition
     * @return
     */
    @PostMapping ("/list")
    public ResponseData<Page> selectPage(@RequestBody Condition<Customer> condition) {
//        Page<WhWarehousing> data=service.selectPage(condition);
        return new ResponseData<Page>(ResultEnums.OK, customerservice.queryAll(condition));
    }
}
